<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="名称" prop="name">
        <el-input v-model="queryParams.name" placeholder="请输入名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="种族" prop="zhongZu">
        <el-input v-model="queryParams.zhongZu" placeholder="请输入种族" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="角色" prop="jueSe">
        <el-input v-model="queryParams.jueSe" placeholder="请输入角色" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="门派" prop="menPai">
        <el-input v-model="queryParams.menPai" placeholder="请输入门派" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['system:mhxyRole:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['system:mhxyRole:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['system:mhxyRole:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['system:mhxyRole:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="mhxyRoleList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="id" align="center" prop="id" />
      <el-table-column label="名称" align="center" prop="name" />
      <el-table-column label="种族" align="center" prop="zhongZu" />
      <el-table-column label="角色" align="center" prop="jueSe" />
      <el-table-column label="门派" align="center" prop="menPai" />
      <el-table-column label="等级" align="center" prop="level" />
      <el-table-column label="生日" align="center" prop="birth" />
      <el-table-column label="乾元丹" align="center" prop="dan" />
      <el-table-column label="潜能点" align="center" prop="qian" />
      <el-table-column label="技能1" align="center" prop="skill1" />
      <el-table-column label="技能2" align="center" prop="skill2" />
      <el-table-column label="技能3" align="center" prop="skill3" />
      <el-table-column label="技能4" align="center" prop="skill4" />
      <el-table-column label="技能5" align="center" prop="skill5" />
      <el-table-column label="技能6" align="center" prop="skill6" />
      <el-table-column label="技能7" align="center" prop="skill7" />
      <el-table-column label="攻击修炼" align="center" prop="rGong" />
      <el-table-column label="法术修炼" align="center" prop="rFa" />
      <el-table-column label="防御修炼" align="center" prop="rFang" />
      <el-table-column label="抗性修炼" align="center" prop="rKang" />
      <el-table-column label="兽攻修炼" align="center" prop="cGong" />
      <el-table-column label="兽法修炼" align="center" prop="cFa" />
      <el-table-column label="兽防修炼" align="center" prop="cFang" />
      <el-table-column label="兽抗修炼" align="center" prop="cKang" />
      <el-table-column label="调息" align="center" prop="tiaoXi" />
      <el-table-column label="打坐" align="center" prop="daZuo" />
      <el-table-column label="仙灵店铺" align="center" prop="xianLing" />
      <el-table-column label="奇门遁甲" align="center" prop="qiMen" />
      <el-table-column label="宝石工艺" align="center" prop="baoShi" />
      <el-table-column label="强身" align="center" prop="qiangShen" />
      <el-table-column label="冥想" align="center" prop="mingXiang" />
      <el-table-column label="健身" align="center" prop="jianShen" />
      <el-table-column label="养生" align="center" prop="yangSheng" />
      <el-table-column label="烹饪" align="center" prop="pengRen" />
      <el-table-column label="中药" align="center" prop="zhongYao" />
      <el-table-column label="暗器" align="center" prop="anQi" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['system:mhxyRole:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['system:mhxyRole:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改梦幻角色对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1200px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row>
          <el-col :span="6">
            <el-form-item label="名称" prop="name">
              <el-input v-model="form.name" placeholder="请输入名称" />
            </el-form-item>
          </el-col>

          <el-col :span="6">
            <el-form-item label="种族" prop="zhongZu">
              <el-select v-model="form.zhongZu" placeholder="请选择种族">
                <el-option v-for="dict in dict.type.mhxy_zhongzu" :key="dict.value" :label="dict.label"
                  :value="dict.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="角色" prop="jueSe">
              <el-input v-model="form.jueSe" placeholder="请输入角色" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="门派" prop="menPai">
              <el-select v-model="form.menPai" placeholder="请选择门派">
                <el-option v-for="dict in dict.type.men_pai" :key="dict.value" :label="dict.label"
                  :value="dict.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="6">
            <el-form-item label="等级" prop="level">
              <el-input v-model="form.level" placeholder="请输入等级" />
            </el-form-item> </el-col>
          <el-col :span="6">
            <el-form-item label="生日" prop="birth">
              <el-input v-model="form.birth" placeholder="请输入生日" />
            </el-form-item> </el-col>
          <el-col :span="6">
            <el-form-item label="乾元丹" prop="dan">
              <el-input v-model="form.dan" placeholder="请输入乾元丹" />
            </el-form-item> </el-col>
          <el-col :span="6">
            <el-form-item label="潜能点" prop="qian">
              <el-input v-model="form.qian" placeholder="请输入潜能点" />
            </el-form-item> </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">

            <el-form-item label="技能1" prop="skill1">
              <el-input v-model="form.skill1" placeholder="请输入技能1" />
            </el-form-item></el-col>
          <el-col :span="6">
            <el-form-item label="技能2" prop="skill2">
              <el-input v-model="form.skill2" placeholder="请输入技能2" />
            </el-form-item></el-col>
          <el-col :span="6">
            <el-form-item label="技能3" prop="skill3">
              <el-input v-model="form.skill3" placeholder="请输入技能3" />
            </el-form-item></el-col>
          <el-col :span="6">
            <el-form-item label="技能4" prop="skill4">
              <el-input v-model="form.skill4" placeholder="请输入技能4" />
            </el-form-item></el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
            <el-form-item label="技能5" prop="skill5">
              <el-input v-model="form.skill5" placeholder="请输入技能5" />
            </el-form-item></el-col>
          <el-col :span="6">
            <el-form-item label="技能6" prop="skill6">
              <el-input v-model="form.skill6" placeholder="请输入技能6" />
            </el-form-item></el-col>
          <el-col :span="6">
            <el-form-item label="技能7" prop="skill7">
              <el-input v-model="form.skill7" placeholder="请输入技能7" />
            </el-form-item></el-col>
        </el-row>

        <el-row>
          <el-col :span="6">
            <el-form-item label="攻击修炼" prop="rGong">
              <el-input v-model="form.rGong" placeholder="请输入攻击修炼" />
            </el-form-item></el-col>
          <el-col :span="6">
            <el-form-item label="法术修炼" prop="rFa">
              <el-input v-model="form.rFa" placeholder="请输入法术修炼" />
            </el-form-item></el-col>
          <el-col :span="6">
            <el-form-item label="防御修炼" prop="rFang">
              <el-input v-model="form.rFang" placeholder="请输入防御修炼" />
            </el-form-item></el-col>
          <el-col :span="6">
            <el-form-item label="抗性修炼" prop="rKang">
              <el-input v-model="form.rKang" placeholder="请输入抗性修炼" />
            </el-form-item></el-col>
        </el-row>

        <el-row>

          <el-col :span="6">
            <el-form-item label="兽攻修炼" prop="cGong">
              <el-input v-model="form.cGong" placeholder="请输入兽攻修炼" />
            </el-form-item></el-col>
          <el-col :span="6">
            <el-form-item label="兽法修炼" prop="cFa">
              <el-input v-model="form.cFa" placeholder="请输入兽法修炼" />
            </el-form-item></el-col>
          <el-col :span="6">
            <el-form-item label="兽防修炼" prop="cFang">
              <el-input v-model="form.cFang" placeholder="请输入兽防修炼" />
            </el-form-item></el-col>
          <el-col :span="6">
            <el-form-item label="兽抗修炼" prop="cKang">
              <el-input v-model="form.cKang" placeholder="请输入兽抗修炼" />
            </el-form-item></el-col>
        </el-row>

        <el-row>
          <el-col :span="6">

            <el-form-item label="调息" prop="tiaoXi">
              <el-input v-model="form.tiaoXi" placeholder="请输入调息" />
            </el-form-item></el-col>
          <el-col :span="6">
            <el-form-item label="打坐" prop="daZuo">
              <el-input v-model="form.daZuo" placeholder="请输入打坐" />
            </el-form-item></el-col>
          <el-col :span="6">
            <el-form-item label="仙灵店铺" prop="xianLing">
              <el-input v-model="form.xianLing" placeholder="请输入仙灵店铺" />
            </el-form-item></el-col>
          <el-col :span="6">
            <el-form-item label="奇门遁甲" prop="qiMen">
              <el-input v-model="form.qiMen" placeholder="请输入奇门遁甲" />
            </el-form-item></el-col>
          <el-col :span="6">
            <el-form-item label="宝石工艺" prop="baoShi">
              <el-input v-model="form.baoShi" placeholder="请输入宝石工艺" />
            </el-form-item></el-col>
        </el-row>

        <el-row>
          <el-col :span="6">
            <el-form-item label="强身" prop="qiangShen">
              <el-input v-model="form.qiangShen" placeholder="请输入强身" />
            </el-form-item></el-col>
          <el-col :span="6">
            <el-form-item label="冥想" prop="mingXiang">
              <el-input v-model="form.mingXiang" placeholder="请输入冥想" />
            </el-form-item></el-col>
          <el-col :span="6">
            <el-form-item label="健身" prop="jianShen">
              <el-input v-model="form.jianShen" placeholder="请输入健身" />
            </el-form-item></el-col>
          <el-col :span="6">
            <el-form-item label="养生" prop="yangSheng">
              <el-input v-model="form.yangSheng" placeholder="请输入养生" />
            </el-form-item></el-col>
        </el-row>

        <el-row>
          <el-col :span="6">
            <el-form-item label="烹饪" prop="pengRen">
              <el-input v-model="form.pengRen" placeholder="请输入烹饪" />
            </el-form-item></el-col>
          <el-col :span="6">
            <el-form-item label="中药" prop="zhongYao">
              <el-input v-model="form.zhongYao" placeholder="请输入中药" />
            </el-form-item></el-col>
          <el-col :span="6">
            <el-form-item label="暗器" prop="anQi">
              <el-input v-model="form.anQi" placeholder="请输入暗器" />
            </el-form-item></el-col>
        </el-row>


      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listMhxyRole, getMhxyRole, delMhxyRole, addMhxyRole, updateMhxyRole } from "@/api/system/mhxyRole";

export default {
  name: "MhxyRole",
  dicts: ['men_pai', 'mhxy_zhongzu'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 梦幻角色表格数据
      mhxyRoleList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        zhongZu: null,
        jueSe: null,
        menPai: null,
        level: null,
        birth: null,
        dan: null,
        qian: null,
        skill1: null,
        skill2: null,
        skill3: null,
        skill4: null,
        skill5: null,
        skill6: null,
        skill7: null,
        rGong: null,
        rFa: null,
        rFang: null,
        rKang: null,
        cGong: null,
        cFa: null,
        cFang: null,
        cKang: null,
        tiaoXi: null,
        daZuo: null,
        xianLing: null,
        qiMen: null,
        baoShi: null,
        qiangShen: null,
        mingXiang: null,
        jianShen: null,
        yangSheng: null,
        pengRen: null,
        zhongYao: null,
        anQi: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询梦幻角色列表 */
    getList() {
      this.loading = true;
      listMhxyRole(this.queryParams).then(response => {
        this.mhxyRoleList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        name: null,
        zhongZu: null,
        jueSe: null,
        menPai: null,
        level: null,
        birth: null,
        dan: null,
        qian: null,
        skill1: null,
        skill2: null,
        skill3: null,
        skill4: null,
        skill5: null,
        skill6: null,
        skill7: null,
        rGong: null,
        rFa: null,
        rFang: null,
        rKang: null,
        cGong: null,
        cFa: null,
        cFang: null,
        cKang: null,
        tiaoXi: null,
        daZuo: null,
        xianLing: null,
        qiMen: null,
        baoShi: null,
        qiangShen: null,
        mingXiang: null,
        jianShen: null,
        yangSheng: null,
        pengRen: null,
        zhongYao: null,
        anQi: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加梦幻角色";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getMhxyRole(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改梦幻角色";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateMhxyRole(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addMhxyRole(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除梦幻角色编号为"' + ids + '"的数据项？').then(function () {
        return delMhxyRole(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/mhxyRole/export', {
        ...this.queryParams
      }, `mhxyRole_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
